// 两数之和:给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。
function twoSum(nums, target) {
    let map = new Map();
    for (let i = 0; i < nums.length; i++) {
        let complement = target - nums[i]; //11,10,9,8,7,...,2
        if (map.has(complement)) {
            return [map.get(complement), i];
        }
        map.set(nums[i], i);//Map { 1 => 0, 2 => 1, 3 => 2, 4 => 3, 5 => 4, 6 => 5, 7 => 6, 8 => 7, 9 => 8 ,10 => 9}
    }
    throw new Error("No two sum solution");
}
let nums=[1,2,3,4,5,6,7,8,9,10];
console.log(twoSum(nums,12))


// 三数之和:给定一个含有 n 个整数的数组,判断该数组是否含有三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组。
